home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / STREAMB.H < prev    next >
C/C++ Source or Header  |  1993-11-23  |  4KB  |  143 lines

  1. /***
  2. *streamb.h - definitions/declarations for the streambuf class
  3. *
  4. *   Copyright (c) 1990-1992, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *   This file defines the classes, values, macros, and functions
  8. *   used by the streambuf class.
  9. *   [AT&T C++]
  10. *
  11. ****/
  12.  
  13. #ifndef _INC_STREAMB
  14. #define _INC_STREAMB
  15.  
  16.  
  17. #ifdef M_I86HM
  18. #define _HFAR_ __far
  19. #else 
  20. #define _HFAR_
  21. #endif 
  22.  
  23. #ifndef NULL
  24. #define NULL    0
  25. #endif 
  26.  
  27. #ifndef EOF
  28. #define EOF (-1)
  29. #endif 
  30.  
  31. // Force word packing to avoid possible -Zp override
  32. #pragma pack(2)
  33.  
  34. #pragma warning(disable:4505)       // disable unwanted /W4 warning
  35. // #pragma warning(default:4505)    // use this to reenable, if necessary
  36.  
  37. typedef long streampos, streamoff;
  38.  
  39. class streambuf {
  40. public:
  41.  
  42.     virtual ~streambuf();
  43.  
  44.     inline int in_avail() const;
  45.     inline int out_waiting() const;
  46.     int sgetc();
  47.     int snextc();
  48.     int sbumpc();
  49.     void stossc();
  50.  
  51.     inline int sputbackc(char);
  52.  
  53.     inline int sputc(int);
  54.     inline int sputn(const char _HFAR_ *,int);
  55.     inline int sgetn(char _HFAR_ *,int);
  56.  
  57.     virtual int sync();
  58.  
  59. //  enum seek_dir { beg=0, cur=1, end=2 };  // CONSIDER: needed ???
  60.  
  61.     virtual streambuf* setbuf(char _HFAR_ *, int);
  62.     virtual streampos seekoff(streamoff,ios::seek_dir,int =ios::in|ios::out);
  63.     virtual streampos seekpos(streampos,int =ios::in|ios::out);
  64.  
  65.     virtual int xsputn(const char _HFAR_ *,int);
  66.     virtual int xsgetn(char _HFAR_ *,int);
  67.  
  68.     virtual int overflow(int =EOF) = 0; // pure virtual function
  69.     virtual int underflow() = 0;    // pure virtual function
  70.  
  71.     virtual int pbackfail(int);
  72.  
  73.     void dbp();
  74.  
  75. protected:
  76.     streambuf();
  77.     streambuf(char _HFAR_ *,int);
  78.  
  79.     inline char _HFAR_ * base() const;
  80.     inline char _HFAR_ * ebuf() const;
  81.     inline char _HFAR_ * pbase() const;
  82.     inline char _HFAR_ * pptr() const;
  83.     inline char _HFAR_ * epptr() const;
  84.     inline char _HFAR_ * eback() const;
  85.     inline char _HFAR_ * gptr() const;
  86.     inline char _HFAR_ * egptr() const;
  87.     inline int blen() const;
  88.     inline void setp(char _HFAR_ *,char _HFAR_ *);
  89.     inline void setg(char _HFAR_ *,char _HFAR_ *,char _HFAR_ *);
  90.     inline void pbump(int);
  91.     inline void gbump(int);
  92.  
  93.     void setb(char _HFAR_ *,char _HFAR_ *,int =0);
  94.     inline int unbuffered() const;
  95.     inline void unbuffered(int);
  96.     int allocate();
  97.     virtual int doallocate();
  98.  
  99. private:
  100.     int _fAlloc;
  101.     int _fUnbuf;
  102.     int x_lastc;
  103.     char _HFAR_ * _base;
  104.     char _HFAR_ * _ebuf;
  105.     char _HFAR_ * _pbase;
  106.     char _HFAR_ * _pptr;
  107.     char _HFAR_ * _epptr;
  108.     char _HFAR_ * _eback;
  109.     char _HFAR_ * _gptr;
  110.     char _HFAR_ * _egptr;
  111. };
  112.  
  113. inline int streambuf::in_avail() const { return (gptr()<_egptr) ? (_egptr-gptr()) : 0; }
  114. inline int streambuf::out_waiting() const { return (_pptr>=_pbase) ? (_pptr-_pbase) : 0; }
  115.  
  116. inline int streambuf::sputbackc(char _c){ return (_eback<gptr()) ? *(--_gptr)=_c : pbackfail(_c); }
  117.  
  118. inline int streambuf::sputc(int _i){ return (_pptr<_epptr) ? (unsigned char)(*(_pptr++)=(char)_i) : overflow(_i); }
  119.  
  120. inline int streambuf::sputn(const char _HFAR_ * _str,int _n) { return xsputn(_str, _n); }
  121. inline int streambuf::sgetn(char _HFAR_ * _str,int _n) { return xsgetn(_str, _n); }
  122.  
  123. inline char _HFAR_ * streambuf::base() const { return _base; }
  124. inline char _HFAR_ * streambuf::ebuf() const { return _ebuf; }
  125. inline int streambuf::blen() const  {return ((_ebuf > _base) ? (_ebuf-_base) : 0); }
  126. inline char _HFAR_ * streambuf::pbase() const { return _pbase; }
  127. inline char _HFAR_ * streambuf::pptr() const { return _pptr; }
  128. inline char _HFAR_ * streambuf::epptr() const { return _epptr; }
  129. inline char _HFAR_ * streambuf::eback() const { return _eback; }
  130. inline char _HFAR_ * streambuf::gptr() const { return _gptr; }
  131. inline char _HFAR_ * streambuf::egptr() const { return _egptr; }
  132. inline void streambuf::gbump(int n) { if (_egptr) _gptr += n; }
  133. inline void streambuf::pbump(int n) { if (_epptr) _pptr += n; }
  134. inline void streambuf::setg(char _HFAR_ * eb, char _HFAR_ * g, char _HFAR_ * eg) {_eback=eb; _gptr=g; _egptr=eg; x_lastc=EOF; }
  135. inline void streambuf::setp(char _HFAR_ * p, char _HFAR_ * ep) {_pptr=_pbase=p; _epptr=ep; }
  136. inline int streambuf::unbuffered() const { return _fUnbuf; }
  137. inline void streambuf::unbuffered(int fUnbuf) { _fUnbuf = fUnbuf; }
  138.  
  139. // Restore default packing
  140. #pragma pack()
  141.  
  142. #endif 
  143.